ShowTable of Contents
How to keep XPages Session Alive without using Extension Library
Thanks to Philippe Riand, he gave me the hint, how to implement a "Keep Session Alive" script, when he was at the SIT GmbH "Lotusphere Comes To You" -Event in Ehningen, Germany.
As you probably know, there is a Component of the XPages Extension Library, called "Keep Session Alive".
But what, if you actually not ready to use the extensions in your XPages application yet. Furthermore you want to set your XPages session timeouts differently to the server settings.
You will find in the application properties (properties.xsp) 2 values, one for the application timeout and one for the session timeout.
In Domino 8.5.2 it is recommended to increase the application timeout, so the JSF Tree is kept in memory for that time. In Domino 8.5.3 you can define if an application or XPage should already be loaded in memory at server start.
The session timeout could be set for short period, e.g. 5 minutes, if you have an application which is used by a high amount of users, and if you are using the Keep Alive feature.
The "Keep Alive" feature pings every half minute before the timeout ends, so the session will stay alive as long the browser is opened.
<xp:scriptBlock id="KeepMySessionAlive">
<xp:this.value><![CDATA[
var dbpath = '#{javascript:facesContext.getExternalContext().getRequestContextPath()}';
var sTimeoutSec = (parseInt('#{javascript:context.getProperty("xsp.session.timeout")}' || 30) * 60) - 30;
if(!XSP.keepAlive)
{XSP.keepAlive=function xe_ka(){
setTimeout('XSP.keepAlive()',sTimeoutSec * 1000);
dojo.xhrGet({url:dbpath + '/xsp/.ibmmodres/ping',
handleAs:'text',
preventCache:true});
};
setTimeout('XSP.keepAlive()',sTimeoutSec * 1000)}
]]></xp:this.value>
</xp:scriptBlock>
If the xsp.session.properties value is not set, script will take 30 minutes by default.
You can copy and paste the Code as it is to your XPages Source Code, or add just the JS code inside the CDATA block to an available ScriptBlock.
Basically this is exactly what the extensions component "Keep Session Alive" does.
Hope this is useful for you.
Regards